import pymysql
from pyecharts.charts import Pie
from pyecharts import options
# 连接数据库
db = pymysql.connect(
    host="localhost",
    port=3306,
    user="root",
    database="crawlerdemo",
    password="123456",
    charset="utf8"
)

cursor = db.cursor()
# 用来查找岗位数量占比最多的6个城市
sql= ("select job_place,count(job_id)/select count(*) from job group by job_place "
      "order by count(job_id)desc limit 6")
try:
    cursor.execute(sql)
    res = cursor.fetchall()
    pie = Pie()
    #饼图只需要一个列表[("类型1"，30),("类型2"，50),......]
    pie.add("单位/个",res)
    pie.set_global_opts(title_opts=options.TitleOpts(title="各城市岗位量占比图"))
    pie.render("pienum.html")
except:
    print("查询出了问题")